package com.tamecode.flowable;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.junit.Test;

/**
 * Flowable 配置
 *
 * @Author: LiQiongchao
 * @Date: 2021/8/10 20:34
 */
public class FlowableConfiguration {


    @Test
    public void loadCWithoutConfigFile() {

//        ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
//        ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();

        ProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration()
                .setJdbcUrl("jdbc:mysql://localhost:3306/flowable?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8")
                .setJdbcDriver("com.mysql.jdbc.Driver")
                .setJdbcUsername("root")
                .setJdbcPassword("root")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        ProcessEngine engine = configuration.buildProcessEngine();
    }

    /**
     * 使用默认加载 Flowable 的配置文件
     */
    @Test
    public void loadConfigTypeOne() {
        /*
        当使用此方式创建 ProcessEngine 时，会从 classpath 下 查找flowable.cfg.xml 的配置文件
         */
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        HolidayRequest.doHolidayRequest(processEngine);
    }

    /**
     *
     * 配置编程的方式加载 Flowable 的配置文件
     * 可以使用配置文件中不同的 bean id 来加载
     */
    @Test
    public void loadConfigTypeTwo() {
        ProcessEngineConfiguration.
                createProcessEngineConfigurationFromResourceDefault();
//        createProcessEngineConfigurationFromResource(String resource);
//        createProcessEngineConfigurationFromResource(String resource, String beanName);
//        createProcessEngineConfigurationFromInputStream(InputStream inputStream);
//        createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName);
    }




}
